export { ReactComponent as Icon } from './icon.svg'
import { getLogger } from '@gnlab/utils'
import config from '@/config'
import { useStreams } from '@/lib/utils'
import services from '@/services'

const logger = getLogger('ui/robot-settings')

export function RobotSettings({ open, onClose }: { open: boolean; onClose: () => void }) {
  const [account] = useStreams(services.auth.account$)

  useEffect(() => {
    if (open && account) {
      const quntoolAPI = encodeURIComponent(config.QUNTOOL_API_FOR_AI_CHAT || location.origin)
      const chatgptSiteURL = `${config.AI_CHAT_SITE}?api=${quntoolAPI}&token=${account.token}`
      logger.info('go site', chatgptSiteURL)
      window.open(chatgptSiteURL)
      onClose()
    }
  }, [open, onClose, account])

  return null
}
